home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
139_01
/
uguide.doc
< prev
next >
Wrap
Text File
|
1985-08-19
|
25KB
|
926 lines
USER'S GUIDE FOR KED
A syntax-directed editor for
KAREL the Robot
A file is a conceptual device used to indicate a place
where your program is stored. Creating or modifying a file
is called editing the file. KED is a syntax-directed editor
for the language used by KAREL the Robot [1] [2]. It allows
you to create or modify syntactically correct programs for
KAREL. This does not mean that your program is a correct
solution to the problem you are trying to solve or that no
"error shutoffs" will result; it means only that there are
no lexical or syntactic errors in your program (see Sec. 2.6
in [1] for a detailed description of the various kinds of
programming errors).
You can use (or invoke) KED by typing:
ked newfilename1 newfilename2
Use any legal filenames you wish. If this is a new program
the names should be different from any in your directory.
The first file is used by KED to keep track of the
relationships in your program. The second file is used to
hold the text of your program in case you should want to
make a printed copy.
If these are new files KED will respond with:
TYPE MN TO SEE MENU
BEGINNING-OF-PROGRAM
<instruction>
This indicates that the first line of your program has been
typed in for you. The flashing underscore indicates where
your typing will start and the word between brackets what
sort of command is legal at this point. Now you can use KED
to create your program. See Editing Session I which creates
a new file.
If you wish to edit an old file, simply use the same
format:
ked oldfilename1 oldfilename2
Here, the first file should be one created in an earlier
session. KED will respond by getting your files and then
printing out the first 20 lines of your program followed by
----------
1. Richard E. Pattis,KAREL the Robot A Gentle Introduction
to the Art of Programming (New York: John Wiley & Sons,
1981)
2. All programs are written in C and compiled by BD Software
C Compiler v1.5.
a ? prompt. Now you can modify your program using the
insert and delete commands.
If by mistake you give an old filename that does not
contain a KAREL program you may exit gracefully by typing
"q" and not saving the program. This will allow you to
start over and not cause any damage to your old file.
Constructs or control structures are used in a program to
change the order of execution of instructions. In KAREL's
language, the constructs begin with IF, WHILE or ITERATE.
Inside the constructs there may be a single statement or
several statements (a compound statement). If a compound
statement is used, it is included between the reserved words
BEGIN and END. If only a single statement is used, in order
to make it clear to KED that the construct is completed, you
must type the NDC (end of construct) command. An NDC is not
needed to complete a construct containing a compound
statement, since an END automatically causes KED to supply
an NDC. An NDC would be required as indicated in the
following program segment:
ITERATE 6 TIMES
turnleft;
NDC (entered by user to complete ITERATE)
IF front-is-blocked
THEN
turnoff
NDC (entered by user to complete THEN)
ELSE
move;
NDC (entered by user to complete ELSE)
WHILE not-facing-north DO
BEGIN
move;
turnleft
END
(no NDC is required to complete WHILE since a compound
statement is used inside the construct)
NDC does not add any statements to your program; it is
only used by KED to structure relationships between
constructs. For editing purposes, IF, THEN and ELSE are
considered to be separate constructs. If any construct but
ELSE follows THEN, KED will automatically perform the NDC so
the instruction will follow the IF.
IF facing-west
THEN
turnleft;
NDC (entered by user to complete THEN)
NDC (automatically performed by KED since the next entry is a
not an ELSE)
pickbeeper;
This can cause some problems if there are several nested
IF's.
IF facing-west
(5) THEN
(4) IF facing-north
(3) THEN
(2) IF facing-south
(1) THEN
move;
NDC
NDC
NDC
NDC
NDC
move;
In order to add the "move" after the outermost IF (the only
legal location, since none of the statements is compound),
NDC must be entered five times to end the indicated
constructs.
To add any of KAREL's instructions or tests to your
program, simply type the one- to three-letter commands at
the desired location and it will be automatically added. If
you make a typing error, the backspace character won't
correct the entry; simply let KED give you an INVALID
COMMAND error message and re-enter the desired instruction.
KED will attempt to guide you through this process with
appropriate prompts for the kind of command to enter. Of
course, you should always have written the complete program
you wish to enter before you sit down at the terminal!
After an instruction has been added, KED will prompt for
the next legal entry: <instruction>, <test>, <new-name> or
<positive-number>. Instructions are always automatically
added to the end of the program.
When you have added a DEFINE-NEW-INSTRUCTION, KED
automatically adds a BEGIN and then will prompt for a new
name; when you have added a WHILE or IF, KED will prompt for
a test; when you have added an ITERATE, KED will prompt for
a positive number. In any of these three situations, you
must respond to the prompt; the only other alternative is to
see the menu. Except for these situations, you can use any
of the edit commands to examine your program at any time
while adding instructions. Whenever you type MN, an updated
menu will be printed at your terminal. User-defined
instructions are added to the menu following the list of
INSTRUCTIONS.
After an instruction has been added, KED will respond with
a prompt